package com.shop2cn.iapi.coupon.testcase.old;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.Collator;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.coupon.parameter.ChooseCouponAutoInProductDetailBean;
import com.shop2cn.iapi.coupon.parameter.CouponInfo;
import com.shop2cn.iapi.coupon.parameter.SellerCoupons;
import com.shop2cn.iapi.coupon.parameter.SellerCouponsList;
import com.shop2cn.iapi.coupon.parameter.ShoppingInfo;
import com.shop2cn.iapi.coupon.service.ChooseCouponAutoInProductDetailCall;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.database.sqlwapper.couponbatchWapper;
/**
*在商详页推荐最优的平台券、买手券、凑单券
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ChooseCouponAutoInProductDetail{
	private static ChooseCouponAutoInProductDetailBean bean;
	private static ChooseCouponAutoInProductDetailCall call;
	private couponWapper couponWapper=new couponWapper();
	private couponbatchWapper batchWapper=new couponbatchWapper();
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	@BeforeClass
	public static void setUp() {
		//bestSellerCoupon根据以平台为主
		//1:传入下一场时间：bestPlatformCoupon,bestSellerCoupon 没有，就用当前，如果有，就用下一场
		//2:传入下一场时间：bestPlatformCoupon没有下一场，bestPlatformCoupon和bestSellerCoupon去取当前
		//3:传入下一场时间：bestPlatformCoupon有下一场，bestPlatformCoupon和bestSellerCoupon去下一场
		//4：easyUsePlatformCoupon,hardUsePlatformCoupon 永远是当前
		Logger.createResultFile("在商详页推荐最优的平台券、买手券、凑单券");
	}

	@Before
	public void caseUp() {
		bean=new ChooseCouponAutoInProductDetailBean();
		call=new ChooseCouponAutoInProductDetailCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private List<CouponInfo> sort(List<CouponInfo> list)
	{
		 if(CollectionUtils.isNotEmpty(list)){
			 Collections.sort(list, new Comparator<CouponInfo>(){  
				  
	             public int compare(CouponInfo o1, CouponInfo o2) {  
	              BigDecimal value1 =o1.getDeductionAmount();//name1是从你list里面拿出来的一个  
	              BigDecimal value2 =o2.getDeductionAmount(); //name1是从你list里面拿出来的第二个name      
	              return value2.compareTo(value1);   
	         } 
			 });
		 }
		 return list;
	}
	private String convertDateStrToAnotherFormat(String date) throws ParseException
	{
		return YMTDateUtil.convertDateStrToAnotherFormat(
				date.substring(0, 19),
                "yyyy-MM-dd HH:mm:ss",
                "yyyy-MM-dd'T'HH:mm:ss");
	}
	private void verifyReturn(boolean... isBestIsNext) throws ParseException, JSONException
	{
		 Logger.verifyEquals("0", call.getErrorCode(), "验证返回Code"); 
	     List<Map> couponInfo=couponWapper.selectCouponInfoByUserId(bean.getShoppingInfo().getBuyerInfo().getBuyerId());
	     
	     List<CouponInfo> platformCoupon=new ArrayList();//保存可以使用的平台优惠券
	     List<CouponInfo> sellerformCoupon=new ArrayList();//保存可以使用的买手优惠券
	     List<CouponInfo> usePlatformCoupon=new ArrayList();//保存凑单集合
	     
	     couponInfo.stream().filter(c->Integer.parseInt(c.get("CreaterType").toString())==1)
	    		 .forEach(p->{
	    	 couponbatch batch=batchWapper.selectByPrimaryKey(Integer.parseInt(p.get("BatchId").toString()));
	    	 
	    	 CouponInfo pinfo=new CouponInfo();
	    	 pinfo.setSellerId(0);
	    	 pinfo.setCouponCode(p.get("CouponCode").toString());
	    	 pinfo.setMeetAmount(batch.getMinOrderValue());
	    	 pinfo.setDeductionAmount(batch.getCouponValue());
	    	 pinfo.setStartTime(p.get("ValidStart").toString());
	    	 pinfo.setEndTime(p.get("ValidEnd").toString());
    		//过滤 订单面额 < 商品价格
	    	 if(batch.getMinOrderValue().compareTo(bean.getShoppingInfo().getAllProducts().get(0).getProductPrice())==-1)
	    	 {
	    		 platformCoupon.add(pinfo);
	    	 }
	    	 else
	    	 {
	    		 usePlatformCoupon.add(pinfo);
	    	 }
	     });
	     //买手优惠券
	     couponInfo.stream().filter(c->Integer.parseInt(c.get("CreaterType").toString())==2)
		 .forEach(p->{
			 couponbatch batch=batchWapper.selectByPrimaryKey(Integer.parseInt(p.get("BatchId").toString()));
	    	 //过滤 订单面额 < 商品价格
	    	 CouponInfo sinfo=new CouponInfo();
	    	 sinfo.setSellerId(batch.getOperatorId());
	    	 sinfo.setCouponCode(p.get("CouponCode").toString());
	    	 sinfo.setMeetAmount(batch.getMinOrderValue());
	    	 sinfo.setDeductionAmount(batch.getCouponValue());
	    	 sinfo.setStartTime(p.get("ValidStart").toString());
	    	 sinfo.setEndTime(p.get("ValidEnd").toString());
	    	 
	    	 if(batch.getMinOrderValue().compareTo(bean.getShoppingInfo().getAllProducts().get(0).getProductPrice())==-1)
	    	 {
	    		 sellerformCoupon.add(sinfo);
	    	 }
		 });
	     //排序
	     List<CouponInfo> bestPlatformCouponlst=sort(platformCoupon);
	     List<CouponInfo> bestSellerCouponlst=sort( sellerformCoupon);
	     List<CouponInfo> useCouponlst=sort( usePlatformCoupon);
	     boolean bestIsNext=false;
        //最佳平台优惠券
	     if(bestPlatformCouponlst.size()>0)
	     {
	    	 if(call.getbestPlatformCoupon()!=null)
	    	 {
	    	    Logger.verifyEquals(0, call.getbestPlatformCoupon().getSellerId(), "验证返回bestPlatformCoupon 中的 sellerId 字段");
	    	   //比较最佳优惠券
	           verify(bestPlatformCouponlst.get(0),call.getbestPlatformCoupon(),"验证返回bestPlatformCoupon与数据库 中的字段");
	    	 }
	        //若最佳平台优惠券 的开始时间> 当前开始时间，则为下一场最佳优惠券
	    	 if(isBestIsNext.length>0)
	    		 bestIsNext=isBestIsNext[0];
	    	 else
	    	 {
			     Date startTime = df.parse(bestPlatformCouponlst.get(0).getStartTime());
			     Date endTime = df.parse(bestPlatformCouponlst.get(0).getEndTime());
			     Date now =df.parse(df.format(new Date()));
			     if(startTime.getTime()>now.getTime() 
			    		 ||(startTime.getTime()<now.getTime() && endTime.getTime()>now.getTime() ) 
			    		 && (bean.getUseCouponDate()!=null && bean.getUseCouponDate().getTime()>now.getTime()))
			    	 bestIsNext=true;
			     else
			    	 bestIsNext=false;
	    	 }
	     }
	     else
	    	 Logger.verifyEquals(null,call.getbestPlatformCoupon(), "验证返回bestPlatformCoupon 为空");
	     //最佳买手优惠券
	     if(bestSellerCouponlst.size()>0)
	         verify(bestSellerCouponlst.get(0),call.getbestSellerCoupon(),"验证返回bestSellerCouponlst与数据库 中的字段","bestSellerCoupon");
	     else
	    	 Logger.verifyEquals(null,call.getbestSellerCoupon(), "验证返回bestSellerCoupon 为空");
	     
	     //是否有凑单优惠券
	     if(useCouponlst.size()>0){
	    	 if(call.geteasyUsePlatformCoupon()!=null)
	    	   Logger.verifyEquals(0, call.geteasyUsePlatformCoupon().getSellerId(), "验证返回easyUsePlatformCoupon 中的 sellerId 字段");
	    	 if(call.gethardUsePlatformCoupon()!=null)
	    	   Logger.verifyEquals(0, call.gethardUsePlatformCoupon().getSellerId(), "验证返回hardUsePlatformCoupon 中的 sellerId 字段");
		     verify(useCouponlst.get(useCouponlst.size()-1),call.geteasyUsePlatformCoupon(),"验证返回easyUsePlatformCoupon与数据库 中的字段");
		     verify(useCouponlst.get(0),call.gethardUsePlatformCoupon(),"验证返回hardUsePlatformCoupon与数据库 中的字段");
	     }
	     else
	     {
	    	 Logger.verifyEquals(null,call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon 为空");
	    	 Logger.verifyEquals(null,call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon 为空");
	     }
	     Logger.verifyEquals(String.valueOf(bestIsNext),call.getBestIsNext(), "验证返回bestIsNext");
	}
	//比较couponInfo 字段值与数据库表值字段
	private void verify(CouponInfo sql_couponInfo ,CouponInfo return_CouponInfo,String desc,String... bestSellerCoupon ) throws ParseException
	{
		//bestSellerCouponlst
		if(bestSellerCoupon.equals("bestSellerCoupon") && call.getbestSellerCoupon()!=null){
		   Logger.verifyEquals(sql_couponInfo.getSellerId(), call.getbestSellerCoupon().getSellerId(), "验证返回bestSellerCoupon 中的 sellerId 字段");
		}
	     Logger.verifyEquals(sql_couponInfo.getCouponCode(), return_CouponInfo.getCouponCode(), desc+"couponCode");
	     Logger.verifyEquals(sql_couponInfo.getMeetAmount().stripTrailingZeros(), return_CouponInfo.getMeetAmount().stripTrailingZeros(), desc+" MeetAmount");
	     Logger.verifyEquals(sql_couponInfo.getDeductionAmount().stripTrailingZeros(), return_CouponInfo.getDeductionAmount().stripTrailingZeros(), desc+" DeductionAmount");
	     Logger.verifyEquals(convertDateStrToAnotherFormat(sql_couponInfo.getStartTime()), return_CouponInfo.getStartTime(), desc+" StartTime");
	     Logger.verifyEquals(convertDateStrToAnotherFormat(sql_couponInfo.getEndTime()), return_CouponInfo.getEndTime(), desc+" EndTime");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_001() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证没有下一场活动");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_001_1() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.DAY_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_002() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证没有下一场活动,无平台优惠券");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
//			// 平台优惠券1
//			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
//			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
//            //平台优惠券2
//            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
//            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
//            listPlatformBean.add(createcouponBean1);
//            listPlatformBean.add(createcouponBean2);
//            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            
			call.setData(bean);
			call.callService();			

			 Logger.verifyEquals(null,call.getbestPlatformCoupon(), "验证返回bestPlatformCoupon 为空");
			 Logger.verifyEquals(null,call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon 为空");
			 Logger.verifyEquals(null,call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon 为空");
			 verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_003() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证没有下一场活动,无买手优惠券");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
//            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
//            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
//            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
//            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
//            listSellercouponBean.add(sellercouponBatchBean);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, null);
            bean.setShoppingInfo(shoppingInfo);
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_004() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证没有下一场活动,凑单券只满足一条");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            //listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_005() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证没有下一场活动,没有满足的平台优惠券和买手优惠券");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
//			// 平台优惠券1
//			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
//			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
//            //平台优惠券2
//            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
//            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));
//
//            // 商家优惠券
//            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
//            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
//            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));
//
//            List<CreateCouponBean> listPlatformBean=new ArrayList();
//            listPlatformBean.add(createcouponBean1);
//            listPlatformBean.add(createcouponBean2);
//            listPlatformBean.add(createcouponBean3);
//            
//            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
//            listSellercouponBean.add(sellercouponBatchBean);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(null, null);
            bean.setShoppingInfo(shoppingInfo);
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_006() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间)");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.DAY_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_007() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有无平台优惠券");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
//			// 平台优惠券1
//			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
//			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
//            //平台优惠券2
//            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
//            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

//            List<CreateCouponBean> listPlatformBean=new ArrayList();
//            listPlatformBean.add(createcouponBean1);
//            listPlatformBean.add(createcouponBean2);
//            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.DAY_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(null, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_008() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有无买手优惠券");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

//            // 商家优惠券
//            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
//            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
//            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
//            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
//            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.DAY_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, null);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_009() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场凑单券只满足一条");
		try {
    		
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));
            
            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
//            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.HOUR_OF_DAY, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
            
			call.setData(bean);
			call.callService();			
			
			verifyReturn();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_010() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场和当前没有满足的平台优惠券和买手优惠券");
		try {
    		
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.HOUR_OF_DAY, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间

    		Calendar calendarend2 = Calendar.getInstance(); // 得到日历
    		calendarend2.setTime(dNow);// 把当前时间赋给日历
    		calendarend2.add(Calendar.HOUR_OF_DAY, 3); // 设置为后1天
    		Date validStartCoupon = calendarend2.getTime(); // 得到前一天的时间
    		
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            Logger.comment("######## shoppingInfo.getBuyerInfo().getBuyerId()  ####### "+shoppingInfo.getBuyerInfo().getBuyerId());
            //修改优惠券时间
           couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).forEach(p->{ 
            	couponWapper.setValidStartByCouponCode(p.get("CouponCode").toString(), validStartCoupon);
            });
            
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
            
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("0", call.getErrorCode(), "验证返回Code");
			Logger.verifyEquals("false", call.getBestIsNext(), "验证返回BestIsNext");
			Logger.verifyEquals(null, call.getbestPlatformCoupon(), "验证返回bestPlatformCoupon");
			Logger.verifyEquals(null, call.getbestSellerCoupon(), "验证返回bestSellerCoupon");
			Logger.verifyEquals(null, call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon");
			Logger.verifyEquals(null, call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_011() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有满足的平台优惠券和买手优惠券,当前有满足平台优惠券和买手优惠券,当前凑单券满足两条");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 3); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
//            //修改优惠券时间
//            couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).forEach(p->{ 
//             	couponWapper.setValidStartByCouponCode(p.get("CouponCode").toString(), validStartCoupon);
//             });
            
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();			
			
			verifyReturn(false);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_012() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有满足的平台优惠券和买手优惠券,当前有满足平台优惠券和买手优惠券,当前凑单券满足一条");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
			
			CreateCouponBean createcouponBean4 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean4.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean4.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(80));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            //listPlatformBean.add(createcouponBean3);
            listPlatformBean.add(createcouponBean4);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 3); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();			
			
			verifyReturn(false);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_013() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有满足的平台优惠券和买手优惠券,当前有满足平台优惠券一种,当前凑单券满足两条");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 3); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();			
			
			verifyReturn(false);			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_014() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有满足的平台优惠券和买手优惠券,当前有满足平台优惠券一种,当前凑单券满足一条");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
//            //平台优惠券3
//            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
//            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
//            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            //listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 3); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();			
			
			verifyReturn(false);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_015() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),下一场没有满足的平台优惠券和买手优惠券,当前有满足买手优惠券一种");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            //listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 3); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
       		Calendar calendarend2 = Calendar.getInstance(); // 得到日历
    		calendarend2.setTime(dNow);// 把当前时间赋给日历
    		calendarend2.add(Calendar.HOUR_OF_DAY, 3); // 设置为后3月
    		Date validStartCoupon = calendarend2.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            Logger.comment("######## shoppingInfo.getBuyerInfo().getBuyerId()  ####### "+shoppingInfo.getBuyerInfo().getBuyerId());
            //修改优惠券时间
           couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream().filter(a->a.get("CreaterType").toString().equals("1"))
           .forEach(p->{ 
            	couponWapper.setValidStartByCouponCode(p.get("CouponCode").toString(), validStartCoupon);
            });
           
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();			
			
			 Logger.verifyEquals(null,call.getbestPlatformCoupon(), "验证返回bestPlatformCoupon 为空");
			 Logger.verifyEquals(null,call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon 为空");
			 Logger.verifyEquals(null,call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon 为空");
			 
			 Optional<Map> couponInfo=  couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream()
					 .filter(a->a.get("CreaterType").toString().equals("2")).findFirst();

	         couponbatch batch=batchWapper.selectByPrimaryKey(Integer.parseInt(couponInfo.get().get("BatchId").toString()));
		     Logger.verifyEquals(couponInfo.get().get("CouponCode"), call.getbestSellerCoupon().getCouponCode(),"验证返回couponCode与数据库比较");
		     Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros(), call.getbestSellerCoupon().getMeetAmount().stripTrailingZeros(), " 验证返回MeetAmount");
		     Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros(), call.getbestSellerCoupon().getDeductionAmount().stripTrailingZeros(), "验证返回 DeductionAmount");
		     Logger.verifyEquals(convertDateStrToAnotherFormat(couponInfo.get().get("ValidStart").toString()), call.getbestSellerCoupon().getStartTime(), "验证返回 StartTime");
		     Logger.verifyEquals(convertDateStrToAnotherFormat(couponInfo.get().get("ValidEnd").toString()), call.getbestSellerCoupon().getEndTime(), "验证返回EndTime");
		     
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_016() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证没有下一场活动(不传入优惠券使用时间),有满足的当前的最佳平台券，没有满足的凑单劵");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, null);
            bean.setShoppingInfo(shoppingInfo);
            
			call.setData(bean);
			call.callService();			
			
			 Logger.verifyEquals("0",call.getErrorCode(), "验证返回ErrorCode 为空");
			 Logger.verifyEquals(null,call.getbestSellerCoupon(), "验证返回bestSellerCoupon 为空");
			 Logger.verifyEquals(null,call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon 为空");
			 Logger.verifyEquals(null,call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon 为空");
			 
			 Optional<Map> couponInfo=  couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream()
					 .filter(a->a.get("CreaterType").toString().equals("1")).findFirst();

	         couponbatch batch=batchWapper.selectByPrimaryKey(Integer.parseInt(couponInfo.get().get("BatchId").toString()));
	         Logger.verifyEquals(0, call.getbestPlatformCoupon().getSellerId(),"验证返回OperatorId与数据库比较");
		     Logger.verifyEquals(couponInfo.get().get("CouponCode"), call.getbestPlatformCoupon().getCouponCode(),"验证返回couponCode与数据库比较");
		     Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros(), call.getbestPlatformCoupon().getMeetAmount().stripTrailingZeros(), " 验证返回MeetAmount");
		     Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros(), call.getbestPlatformCoupon().getDeductionAmount().stripTrailingZeros(), "验证返回 DeductionAmount");
		     Logger.verifyEquals(convertDateStrToAnotherFormat(couponInfo.get().get("ValidStart").toString()), call.getbestPlatformCoupon().getStartTime(), "验证返回 StartTime");
		     Logger.verifyEquals(convertDateStrToAnotherFormat(couponInfo.get().get("ValidEnd").toString()), call.getbestPlatformCoupon().getEndTime(), "验证返回EndTime");
		     
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_017() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),有满足下场的最佳平台券，没有满足下场最佳的买手券，返回下场最佳平台，买手为空");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
       		Calendar calendarend2 = Calendar.getInstance(); // 得到日历
    		calendarend2.setTime(dNow);// 把当前时间赋给日历
    		calendarend2.add(Calendar.HOUR_OF_DAY, 3); // 设置为后3月
    		Date validStartCoupon = calendarend2.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            Logger.comment("######## shoppingInfo.getBuyerInfo().getBuyerId()  ####### "+shoppingInfo.getBuyerInfo().getBuyerId());
            //修改优惠券时间
           couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream().filter(a->a.get("CreaterType").toString().equals("1"))
           .forEach(p->{ 
            	couponWapper.setValidStartByCouponCode(p.get("CouponCode").toString(), validStartCoupon);//只修改第一条最大优惠券
            });
            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();	
		    
			 Logger.verifyEquals("0",call.getErrorCode(), "验证返回ErrorCode 为空");
			 Logger.verifyEquals("true",call.getBestIsNext(), "验证返回BestIsNext 为空");
			 Logger.verifyEquals(null,call.getbestSellerCoupon(), "验证返回bestSellerCoupon 为空");
			 Logger.verifyEquals(null,call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon 为空");
			 Logger.verifyEquals(null,call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon 为空");
			 
			 Optional<Map> couponInfo=  couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream()
					 .filter(a->a.get("CreaterType").toString().equals("1")).findFirst();

	         couponbatch batch=batchWapper.selectByPrimaryKey(Integer.parseInt(couponInfo.get().get("BatchId").toString()));
	         Logger.verifyEquals(0, call.getbestPlatformCoupon().getSellerId(),"验证返回OperatorId与数据库比较");
		     Logger.verifyEquals(couponInfo.get().get("CouponCode"), call.getbestPlatformCoupon().getCouponCode(),"验证返回couponCode与数据库比较");
		     Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros(), call.getbestPlatformCoupon().getMeetAmount().stripTrailingZeros(), " 验证返回MeetAmount");
		     Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros(), call.getbestPlatformCoupon().getDeductionAmount().stripTrailingZeros(), "验证返回 DeductionAmount");
		     Logger.verifyEquals(convertDateStrToAnotherFormat(couponInfo.get().get("ValidStart").toString()), call.getbestPlatformCoupon().getStartTime(), "验证返回 StartTime");
		     Logger.verifyEquals(convertDateStrToAnotherFormat(couponInfo.get().get("ValidEnd").toString()), call.getbestPlatformCoupon().getEndTime(), "验证返回EndTime");
		     
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_018() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),有满足下场的最佳买手券，没有满足下场最佳和当前的平台券，返回都为空");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
       		Calendar calendarend2 = Calendar.getInstance(); // 得到日历
    		calendarend2.setTime(dNow);// 把当前时间赋给日历
    		calendarend2.add(Calendar.HOUR_OF_DAY, -1); // 设置为后3月
    		Date validEndCoupon = calendarend2.getTime(); // 得到前一天的时间
    		
       		Calendar calendarend3 = Calendar.getInstance(); // 得到日历
       		calendarend3.setTime(dNow);// 把当前时间赋给日历
       		calendarend3.add(Calendar.HOUR_OF_DAY, 4); // 设置为后3月
    		Date sellerStratCoupon = calendarend3.getTime(); // 得到前一天的时间
    		
       		Calendar calendarend4 = Calendar.getInstance(); // 得到日历
       		calendarend4.setTime(dNow);// 把当前时间赋给日历
       		calendarend4.add(Calendar.WEEK_OF_MONTH, 4); // 设置为后3月
    		Date sellerEndCoupon = calendarend4.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            Logger.comment("######## shoppingInfo.getBuyerInfo().getBuyerId()  ####### "+shoppingInfo.getBuyerInfo().getBuyerId());
            //修改优惠券时间
           couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream().filter(a->a.get("CreaterType").toString().equals("1"))
           .forEach(p->{ 
            	couponWapper.setValidEndByCouponCode(p.get("CouponCode").toString(), validEndCoupon);
            });
           //买手
           couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream().filter(a->a.get("CreaterType").toString().equals("2"))
           .forEach(p->{ 
            	couponWapper.setValidStartByCouponCode(p.get("CouponCode").toString(), sellerStratCoupon);
            	couponWapper.setValidEndByCouponCode(p.get("CouponCode").toString(), sellerEndCoupon);
            });
           //下一场 传入时间， 如果有下场买手，没有下一场平台，返回下一场最佳买手，最佳平台为null

            bean.setShoppingInfo(shoppingInfo);
            bean.setNextShoppingInfo(shoppingInfo);
            bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();	
		    
			 Logger.verifyEquals("0",call.getErrorCode(), "验证返回ErrorCode 为空");
			 Logger.verifyEquals("false",call.getBestIsNext(), "验证返回BestIsNext 为空");
			 Logger.verifyEquals(null,call.getbestPlatformCoupon(), "验证返回bestPlatformCoupon 为空");
			 Logger.verifyEquals(null,call.getbestSellerCoupon(), "验证返回bestSellerCoupon 为空");
			 Logger.verifyEquals(null,call.geteasyUsePlatformCoupon(), "验证返回easyUsePlatformCoupon 为空");
			 Logger.verifyEquals(null,call.gethardUsePlatformCoupon(), "验证返回hardUsePlatformCoupon 为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChooseCouponAutoInProductDetail_019() {
		Logger.start(true,"在商详页推荐最优的平台券、买手券、凑单券-验证有下一场活动(传入优惠券使用时间),有满足下场的最佳平台券，没有满足下场凑单劵,但是有满足当前的凑单券,"
				+ "返回下场最佳平台券,凑单券（凑单券始终是返回当前的）");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			// 平台优惠券1
			CreateCouponBean createcouponBean1 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean1.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(100));
			createcouponBean1.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(90));
            //平台优惠券2
            CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
			createcouponBean2.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(1500));
            createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(15));
            //平台优惠券3
            CreateCouponBean createcouponBean3 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();		
            createcouponBean3.getCouponValues().get(0).setOrderMinAmount(new BigDecimal(2000));
            createcouponBean3.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(200));

            // 商家优惠券
            SellerCreateBatchBean sellercouponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
            sellercouponBatchBean.setCouponAmount(new BigDecimal(10));
            sellercouponBatchBean.setOrderMinAmount(new BigDecimal(20));

            List<CreateCouponBean> listPlatformBean=new ArrayList();
            listPlatformBean.add(createcouponBean1);
            listPlatformBean.add(createcouponBean2);
            listPlatformBean.add(createcouponBean3);
            
            List<SellerCreateBatchBean> listSellercouponBean=new ArrayList();
            listSellercouponBean.add(sellercouponBatchBean);
            
        	Date dNow = new Date(); // 当前时间
    		Calendar calendarend = Calendar.getInstance(); // 得到日历
    		calendarend.setTime(dNow);// 把当前时间赋给日历
    		calendarend.add(Calendar.WEEK_OF_MONTH, 1); // 设置为后1天
    		Date useCouponDate = calendarend.getTime(); // 得到前一天的时间
    		
       		Calendar calendarend2 = Calendar.getInstance(); // 得到日历
    		calendarend2.setTime(dNow);// 把当前时间赋给日历
    		calendarend2.add(Calendar.HOUR_OF_DAY, 3); // 设置为后3月
    		Date validStartCoupon = calendarend2.getTime(); // 得到前一天的时间
    		
            ShoppingInfo shoppingInfo = setChooseCouponAutoBean(listPlatformBean, listSellercouponBean);
            Logger.comment("######## shoppingInfo.getBuyerInfo().getBuyerId()  ####### "+shoppingInfo.getBuyerInfo().getBuyerId());
            //修改优惠券时间
            int count=0;
            Optional<Map> map= couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId())
           .stream().filter(a->a.get("CreaterType").toString().equals("1")).findFirst();
            couponWapper.setValidStartByCouponCode(map.get().get("CouponCode").toString(), validStartCoupon);//只修改第一条最大优惠券
        
			bean.setShoppingInfo(shoppingInfo);
			bean.setNextShoppingInfo(shoppingInfo);
			bean.setUseCouponDate(useCouponDate);//下场时间
			call.setData(bean);
			call.callService();	
			
			 Logger.verifyEquals("0",call.getErrorCode(), "验证返回ErrorCode 为空");
			 Logger.verifyEquals("true",call.getBestIsNext(), "验证返回BestIsNext 为空");
			 Logger.verifyEquals(null,call.getbestSellerCoupon(), "验证返回bestSellerCoupon 为空");
			 couponWapper.selectCouponInfoByUserId(shoppingInfo.getBuyerInfo().getBuyerId()).stream()
			 .filter(a->a.get("CreaterType").toString().equals("1")).forEach(p->{
				 couponbatch batch=batchWapper.selectByPrimaryKey(Integer.parseInt(p.get("BatchId").toString()));
		         //bestPlatformCoupon
		         if(batch.getMinOrderValue().compareTo(createcouponBean1.getCouponValues().get(0).getOrderMinAmount())==0)
		         {
			         Logger.verifyEquals(0, call.getbestPlatformCoupon().getSellerId(),"验证返回OperatorId与数据库比较");
				     Logger.verifyEquals(p.get("CouponCode"), call.getbestPlatformCoupon().getCouponCode(),"验证返回couponCode与数据库比较");
				     Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros(), call.getbestPlatformCoupon().getMeetAmount().stripTrailingZeros(), " 验证返回MeetAmount");
				     Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros(), call.getbestPlatformCoupon().getDeductionAmount().stripTrailingZeros(), "验证返回 DeductionAmount");
				     try {
						Logger.verifyEquals(convertDateStrToAnotherFormat(p.get("ValidStart").toString()), call.getbestPlatformCoupon().getStartTime(), "验证返回 StartTime");
					    Logger.verifyEquals(convertDateStrToAnotherFormat(p.get("ValidEnd").toString()), call.getbestPlatformCoupon().getEndTime(), "验证返回EndTime");
					} catch (Exception e) {	}
		         }
		         //easyUsePlatformCoupon
		         else if(batch.getMinOrderValue().compareTo(createcouponBean2.getCouponValues().get(0).getOrderMinAmount())==0)
		         {
		        	 Logger.verifyEquals(0, call.geteasyUsePlatformCoupon().getSellerId(),"验证返回OperatorId与数据库比较");
				     Logger.verifyEquals(p.get("CouponCode"), call.geteasyUsePlatformCoupon().getCouponCode(),"验证返回couponCode与数据库比较");
				     Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros(), call.geteasyUsePlatformCoupon().getMeetAmount().stripTrailingZeros(), " 验证返回MeetAmount");
				     Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros(), call.geteasyUsePlatformCoupon().getDeductionAmount().stripTrailingZeros(), "验证返回 DeductionAmount");
				     try {
						Logger.verifyEquals(convertDateStrToAnotherFormat(p.get("ValidStart").toString()), call.geteasyUsePlatformCoupon().getStartTime(), "验证返回 StartTime");
					    Logger.verifyEquals(convertDateStrToAnotherFormat(p.get("ValidEnd").toString()), call.geteasyUsePlatformCoupon().getEndTime(), "验证返回EndTime");
					} catch (Exception e) {	}
		         }
		         //hardUsePlatformCoupon
		         else if(batch.getMinOrderValue().compareTo(createcouponBean3.getCouponValues().get(0).getOrderMinAmount())==0)
		         {
		        	 Logger.verifyEquals(0, call.gethardUsePlatformCoupon().getSellerId(),"验证返回OperatorId与数据库比较");
				     Logger.verifyEquals(p.get("CouponCode"), call.gethardUsePlatformCoupon().getCouponCode(),"验证返回couponCode与数据库比较");
				     Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros(), call.gethardUsePlatformCoupon().getMeetAmount().stripTrailingZeros(), " 验证返回MeetAmount");
				     Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros(), call.gethardUsePlatformCoupon().getDeductionAmount().stripTrailingZeros(), "验证返回 DeductionAmount");
				     try {
						Logger.verifyEquals(convertDateStrToAnotherFormat(p.get("ValidStart").toString()), call.gethardUsePlatformCoupon().getStartTime(), "验证返回 StartTime");
					    Logger.verifyEquals(convertDateStrToAnotherFormat(p.get("ValidEnd").toString()), call.gethardUsePlatformCoupon().getEndTime(), "验证返回EndTime");
					} catch (Exception e) {	}
		         }
		         
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private ShoppingInfo setChooseCouponAutoBean(List<CreateCouponBean> listPlatformcouponBean, List<SellerCreateBatchBean> listSellercouponBean)
	            throws ClientProtocolException, IOException, InterruptedException
	    {
	       // int userId = Integer.parseInt(EnvSetup.getData("couponBuyerId"));
	    	int userId =Integer.parseInt(TestDataManager.getRandomNum(8));
	    	Logger.comment("###  userId   ###  "+userId);
	        CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();

	        // 平台优惠券
	        String platformcouponCode = null;
	        if (listPlatformcouponBean!=null && listPlatformcouponBean.size()>0)
	        {
	            // createcouponBean
	        	for(CreateCouponBean cbean:listPlatformcouponBean){
		            String batchcode2 = couponCallService.createPlatformCoupon(cbean).getBatchCode();
		            platformcouponCode = couponCallService.receiveCouponInfo(batchcode2, userId).getUserReceiveResult().getCouponCode();
	        	}
	        }

	        // 商家优惠券
	        String sellerCouponCode = null;
	        ShoppingInfo shoppingInfo;
	        if (listSellercouponBean!=null && listSellercouponBean.size()>0)
	        {
	        	for( SellerCreateBatchBean sellerbean:listSellercouponBean)
	        	{
		            String batchCode1 = couponCallService.SellerCreateBatch(sellerbean).getBatchCode();
		            sellerCouponCode = couponCallService.receiveCouponInfo(batchCode1, userId).getUserReceiveResult().getCouponCode();
	        	}
//	            shoppingInfo =
//	                    couponCallService.setDefaultShoppingInfo(userId, couponBatchBean.getSellerId(),platformcouponCode, sellerCouponCode);
	            shoppingInfo =
	                    CouponShop2cnMCallService.setDefaultShoppingInfo(userId, listSellercouponBean.get(0).getSellerId(),null, sellerCouponCode);
	        }
	        else {
//	        	 shoppingInfo =
//	                     couponCallService.setDefaultShoppingInfo(userId,platformcouponCode, sellerCouponCode);
	        	 shoppingInfo =
	                     CouponShop2cnMCallService.setDefaultShoppingInfo(userId,null, sellerCouponCode);
	             
			}

	        return shoppingInfo;
	    }
}